package com.aforce3.trailertracer.scenes;

import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;

import com.aforce3.trailertracer.Ray;
import com.aforce3.trailertracer.utils.VectorModifier;

public abstract class Shape extends Primitive
{
	float indexOfRefraction = 2f;

	public Ray calculateRefraction(Ray ray, Point3d intersect){
		//assume air / vacumn index = 1
		
		//part 1: calculate innerVector (vector inside the shape)
		
		Vector3d normal = getNormal(ray);
		
		Vector3d innerVector = VectorModifier.calculateVectorRefraction(ray.getDirection(), normal, 1, indexOfRefraction);
		
		//part 2 calculate intersect point on the other side and output vector
		Ray innerRay = new Ray(intersect, innerVector, ray.depth);
		
		normal = getNormal(innerRay);
		//this normal needs to face inwards
		normal.scale(-1);
		
		Vector3d returnVector = VectorModifier.calculateVectorRefraction(innerRay.getDirection(), normal, indexOfRefraction, 1);
		Point3d returnIntersect = calculateIntersect(innerRay);
		Ray returnRay = new Ray(returnIntersect, returnVector, ray.depth + 1);
	
		
		//debug compare incoming and outgoing rays (direction should be the same)
		
		//System.out.println("INCOMING: " + intersect + "   OUTGOING: " + returnRay.getSource());
		//System.out.println(ray.getDirection() + " : " + returnRay.getDirection());
		//System.out.println(getDistance(innerRay));
		
		return returnRay;
	}
	
	public abstract Vector3d getNormal(Point3d point);
}
